package com.kejiguan.ui.util;

import android.text.TextUtils;

import com.kejiguan.ui.model.DisplayArea;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.model.MenuItem;
import com.kejiguan.ui.model.SystemUser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by apple on 16/4/16.
 */
public class CacheDataUtil {

    private SystemUser mUser;
    private List<MenuItem> menuItems;
    private List<DisplayArea> displayAreas;
    private List<String> disPlayAreaIdNames;
    private HashMap<String,String> operationRecord;

    private List<ExhibitionNeItem> alarmExhibitionNeItems;

    private int totalCount=0;
    private int totalRunningCount=0;
    private int totalexitCount=0;


    private static CacheDataUtil instance;

    public static CacheDataUtil getInstance() {
        if (instance == null) {
            synchronized (CacheDataUtil.class) {
                if (instance == null) {
                    instance = new CacheDataUtil();
                }
            }
        }
        return instance;
    }


    public CacheDataUtil()
    {
        operationRecord=new HashMap<>();
    }

    public SystemUser getmUser() {
        return mUser;
    }

    public void setmUser(SystemUser mUser) {
        this.mUser = mUser;
    }

    public List<MenuItem> getMenuItems() {
        return menuItems;
    }

    public void setMenuItems(List<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    public static void setInstance(CacheDataUtil instance) {
        CacheDataUtil.instance = instance;
    }

    public List<DisplayArea> getDisplayAreas() {
        return displayAreas;
    }

    public void setDisplayAreas(List<DisplayArea> displayAreas) {
        this.displayAreas = displayAreas;
    }

    public List<String> getDisPlayAreaIdNames() {
        return disPlayAreaIdNames;
    }

    public void setDisPlayAreaIdNames(List<String> disPlayAreaIdNames) {
        this.disPlayAreaIdNames = disPlayAreaIdNames;
    }

    public HashMap<String, String> getOperationRecord() {
        return operationRecord;
    }

    public void setOperationRecord(HashMap<String, String> operationRecord) {
        this.operationRecord = operationRecord;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalRunningCount() {
        return totalRunningCount;
    }

    public void setTotalRunningCount(int totalRunningCount) {
        this.totalRunningCount = totalRunningCount;
    }

    public int getTotalexitCount() {
        return totalexitCount;
    }

    public void setTotalexitCount(int totalexitCount) {
        this.totalexitCount = totalexitCount;
    }

//    public List<ExhibitionNeItem> getAlarmExhibitionNeItems() {
//        return alarmExhibitionNeItems;
//    }

    public void setAlarmExhibitionNeItems(List<ExhibitionNeItem> alarmExhibitionNeItems) {
        this.alarmExhibitionNeItems = alarmExhibitionNeItems;
    }

    public List<ExhibitionNeItem> getAlarmExhibitionNeItems(String alarmContent) {
        alarmExhibitionNeItems=new ArrayList<>(0);
        if (!TextUtils.isEmpty(alarmContent))
        {

                    for (int i=0;i<CacheDataUtil.getInstance().getDisplayAreas().size();i++)
                    {
                        DisplayArea displayArea= CacheDataUtil.getInstance().getDisplayAreas().get(i);
                        displayArea.initDatas();

                        List<ExhibitionNeItem> neItems=displayArea.getExhibitionNeItems();
                        if (null!=neItems)
                        {
                            for (int z=0;z<neItems.size();z++)
                            {
                                ExhibitionNeItem neItem=neItems.get(z);
                                if (alarmContent.contains(neItem.getExhibitionName()))
                                {
                                    alarmExhibitionNeItems.add(neItem);
                                }
                            }
                        }
                    }
        }
        return alarmExhibitionNeItems;
    }
}
